import request from '@/utils/request'

export function getReceiptPayment(data) {
  return request({
    url: '/rp/receiptPayment/getResPageData',
    method: 'post',
    data
  })
}

export function delReceiptPayment(id) {
  return request({
    url: '/rp/receiptPayment/deleteByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function getByHeaderId(id) {
  return request({
    url: '/rp/receiptPayment/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function saveReceiptPayment(data) {
  return request({
    url: '/rp/receiptPayment/save',
    method: 'post',
    data
  })
}

export function buildReceiptPayment(data) {
  return request({
    url: '/rp/receiptPayment/buildVoucherByHeaderId',
    method: 'post',
    data
  })
}

export function auditReceiptPayment(data) {
  return request({
    url: '/rp/receiptPayment/auditByHeaderId',
    method: 'post',
    data
  })
}

export function printByHeaderId(id) {
  return request({
    url: '/rp/receiptPayment/printByHeaderId',
    method: 'post',
    data: { id }
  })
}

// 获取销售单据
export function getSalesListByCustId(data) {
  return request({
    url: '/rp/receiptPayment/getBySupplierIdOrCustId',
    method: 'post',
    data
  })
}

// 获取采购单据
export function getPurchaseListBySupplierId(data) {
  return request({
    url: '/rp/receiptPayment/getBySupplierIdOrCustId',
    method: 'post',
    data
  })
}

// 查看审核意见
export function getAuditInfoByHeaderId(id) {
  return request({
    url: '/log/auditInfo/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function printPDF(path, data) {
  return request({
    url: '/' + path + '/printPDF',
    method: 'post',
    data
  })
}

export function exportExcel(path, data) {
  const exportUrl = '/' + path + '/exportExcel'
  var temp = document.createElement('form')
  temp.action = exportUrl
  temp.method = 'POST'
  temp.style.display = 'none'
  for (var x in data.queryParam) {
    var opt = document.createElement('textarea')
    opt.name = x
    opt.value = data.queryParam[x] || null
    temp.appendChild(opt)
  }
  document.body.appendChild(temp)
  temp.submit()
  return temp
}
